
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

# qq 登录

driver = webdriver.Firefox()
driver.get("https://qzone.qq.com/")


# 定位到frame
login_frame = driver.find_element(by=By.ID,value="login_frame")
#切换frame
driver.switch_to.frame(login_frame)

# 找到 账号密码登录，点击,因为它是在iframe里面的，所以需要切换了frame才能找到
u_p_login = driver.find_element(by=By.ID,value="switcher_plogin")
u_p_login.click()

# 切换完成就可以查找frame/iframe里面的元素了
# qq 输入框
user = driver.find_element(by=By.ID,value="u")
user.send_keys("344497381")
time.sleep(3)

# 密码输入框
password = driver.find_element(by=By.ID,value="p")
password.send_keys("123456")
time.sleep(3)

# 登录按钮
btn = driver.find_element(by=By.CLASS_NAME,value="btn")
btn.click()
time.sleep(10)

# 关闭当前窗口
driver.close()